package com.qyhl.webtv.module_live.teletext.sandulive;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.launcher.ARouter;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.webtv.basiclib.base.BaseFragment;
import com.qyhl.webtv.commonlib.constant.ServicePathConstant;
import com.qyhl.webtv.commonlib.service.NewsService;
import com.qyhl.webtv.module_live.R;
import com.qyhl.webtv.module_live.R2;
import com.qyhl.webtv.module_live.teletext.mixlive.MixLiveListFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class SDLiveFragment extends BaseFragment {
    @BindView(R2.id.tabLayout)
    SlidingTabLayout tabLayout;
    @BindView(R2.id.view_pager)
    ViewPager viewPager;

    @Autowired(name = ServicePathConstant.NEWS_SERVICE)
    public NewsService newsService;

    private String sectionId;

    public void setSectionId(String sectionId) {
        this.sectionId = sectionId;
    }

    public static SDLiveFragment newInstance(String sectionId) {
        SDLiveFragment fragment = new SDLiveFragment();
        fragment.setSectionId(sectionId);
        return fragment;
    }

    @SuppressLint("InflateParams")
    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.live_fragment_sandu_live, null);
    }

    @Override
    public void initImmersionBar() {

        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .statusBarColor(R.color.white)
                .fitsSystemWindows(true)
                .init();

    }

    @Override
    protected void create() {
        ARouter.getInstance().inject(this);
        List<String> nameList = new ArrayList<>();
        List<Fragment> fragmentList = new ArrayList<>();
        nameList.add("直播");
        nameList.add("点播");

        fragmentList.add(MixLiveListFragment.newInstance("", ""));
        fragmentList.add(newsService.getSDColumnFragment(sectionId, 1));

        viewPager.setAdapter(new Adapter(getChildFragmentManager(), fragmentList, nameList));
        tabLayout.setViewPager(viewPager);
    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void onFirstVisible() {

    }

    @Override
    protected void onVisible() {

    }

    @Override
    protected void onHide() {

    }

    static class Adapter extends FragmentPagerAdapter {
        private List<Fragment> fragmentList;
        private List<String> names;

        public Adapter(FragmentManager fm, List<Fragment> fragmentList, List<String> names) {
            super(fm);
            this.fragmentList = fragmentList;
            this.names = names;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names.get(position);
        }
    }
}
